'''
Created on Apr 3, 2012

@author: Johnathon
'''
from Gates.NANDGate import NandGate
from LineValues import Zero, One
from Wire import Wire
import Simulator
import unittest


class Test(unittest.TestCase):


    def setUp(self):
        self.input1 = Wire("input1", 0, None, [])
        self.input11 = Wire("input11", 0, self.input1, [])
        self.input12 = Wire("input12", 0, self.input1, [])
        self.input1.destinations = [self.input11, self.input12]
        
        self.input2 = Wire("input2", 0, None, [])
        self.input21 = Wire("input21", 0, self.input2, [])
        self.input22 = Wire("input22", 0, self.input2, [])
        self.input2.destinations = [self.input21, self.input22]
        
        self.middleOut = Wire("middleOut", 1, None, [])
        self.middle1 = Wire("middle1", 1, self.middleOut, [])
        self.middle2 = Wire("middle2", 1, self.middleOut, [])
        self.middleOut.destinations = [self.middle1, self.middle2]
        
        self.topOut = Wire("topOut", 1, None, [])
        self.bottomOut = Wire("bottomOut", 1, None, [])
        self.output = Wire("output", 2, None, [])
        
        self.middleNAND = NandGate("middleNAND", 1, [self.input11, self.input21], self.middleOut)
        self.topNAND = NandGate("topNAND", 2, [self.input12, self.middleOut], self.topOut)
        self.bottomNAND = NandGate("bottomNAND", 2, [self.input22, self.middleOut], self.bottomOut)
        self.lastNAND = NandGate("lastNAND", 3, [self.bottomOut, self.topOut], self.output)
        
        self.sim = Simulator
        


    def tearDown(self):
        pass


    def testName(self):
        for x1 in [Zero, One]:
            for x2 in [Zero, One]:
                result = self.sim.simulate([x1, x2], [self.input1, self.input2], [self.output], [self.input1, self.input2,
                                                                                        self.middleOut, self.topOut, self.bottomOut,
                                                                                        self.output], 
                                                                                       [[self.middleNAND], [self.topNAND, self.bottomNAND], [self.lastNAND]])
                result = result['output'][0]
                print "(" + x1.__repr__() + ", " + x2.__repr__() + ") " + result.__repr__() + " " + x1.XOR(x2).__repr__()
                self.assertTrue(result is x1.XOR(x2))


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()